package cn.stylefeng.guns.modular.level.controller;

import cn.stylefeng.guns.modular.level.entity.Level;
import cn.stylefeng.guns.modular.level.pojo.request.LevelRequest;
import cn.stylefeng.guns.modular.level.service.LevelService;
import cn.stylefeng.roses.kernel.scanner.api.annotation.ApiResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.GetResource;
import cn.stylefeng.roses.kernel.scanner.api.annotation.PostResource;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import cn.stylefeng.roses.kernel.rule.pojo.response.ResponseData;
import cn.stylefeng.roses.kernel.rule.pojo.response.SuccessResponseData;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 控制器
 *
 * @author xbz
 * @date 2023/04/19 10:35
 */
@RestController
@ApiResource(name = "")
public class LevelController {

    @Resource
    private LevelService levelService;

    /**
     * 添加
     *
     * @author xbz
     * @date 2023/04/19 10:35
     */
    @PostResource(name = "添加", path = "/level/add",requiredPermission = false,requiredLogin = false)
    public ResponseData<Level> add(@RequestBody @Validated(LevelRequest.add.class) LevelRequest levelRequest) {
        levelService.add(levelRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 删除
     *
     * @author xbz
     * @date 2023/04/19 10:35
     */
    @PostResource(name = "删除", path = "/level/delete",requiredPermission = false,requiredLogin = false)
    public ResponseData<?> delete(@RequestBody @Validated(LevelRequest.delete.class) LevelRequest levelRequest) {
        levelService.del(levelRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 编辑
     *
     * @author xbz
     * @date 2023/04/19 10:35
     */
    @PostResource(name = "编辑", path = "/level/edit",requiredPermission = false,requiredLogin = false)
    public ResponseData<?> edit(@RequestBody @Validated(LevelRequest.edit.class) LevelRequest levelRequest) {
        levelService.edit(levelRequest);
        return new SuccessResponseData<>();
    }

    /**
     * 查看详情
     *
     * @author xbz
     * @date 2023/04/19 10:35
     */
    @GetResource(name = "查看详情", path = "/level/detail",requiredPermission = false,requiredLogin = false)
    public ResponseData<Level> detail(@Validated(LevelRequest.detail.class) LevelRequest levelRequest) {
        return new SuccessResponseData<>(levelService.detail(levelRequest));
    }

    /**
     * 获取列表
     *
     * @author xbz
     * @date 2023/04/19 10:35
     */
    @GetResource(name = "获取列表", path = "/level/list",requiredPermission = false,requiredLogin = false)
    public ResponseData<List<Level>> list(LevelRequest levelRequest) {
        return new SuccessResponseData<>(levelService.findList(levelRequest));
    }

    /**
     * 获取列表（带分页）
     *
     * @author xbz
     * @date 2023/04/19 10:35
     */
    @GetResource(name = "分页查询", path = "/level/page",requiredPermission = false,requiredLogin = false)
    public ResponseData<PageResult<Level>> page(LevelRequest levelRequest) {
        return new SuccessResponseData<>(levelService.findPage(levelRequest));
    }


    @GetResource(name = "等级查询", path = "/level/selectPage",requiredPermission = false,requiredLogin = false)
    public ResponseData<PageResult<Level>> selectPage(Integer pageNo, Integer pageSize) {
        return new SuccessResponseData<>(levelService.selectPage( pageNo, pageSize));
    }
}
